<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'north'" style="height:40px">
<div style="float:left;padding:5px 0 0 5px;">
	<a href="javascript:void(0)" onclick="$('#conditionWin2').window('open');" class="easyui-linkbutton" data-options="iconCls:'icon-search'">筛选学生</a>
	<span style="margin-left:20px;">当前筛选条件：</span><span id="currentCondition2" style="display:inline-block;vertical-align:sub;color:red;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;width:350px;">全部学生</span>
</div>
	</div>
    <div data-options="region:'center'">
<table class="easyui-datagrid" id="smList" 
  		data-options="url:'user/freezeStus',fit:true,fitColumns:true,rownumbers:true,pagination:true,pageSize:20,pageList:[20,50,100,200,500,1000],toolbar:smToolbar,rowStyler:stuRowStyler2,loadFilter:freeStuRender2">
  	<thead>
        <tr>
        	<th data-options="field:'ck',checkbox:true"></th>
            <th data-options="field:'xm',halign:'center',width:60,formatter:formatNameLink">姓名</th>
            <th data-options="field:'lqyxsmc',halign:'center',width:120">系别名称</th>
            <th data-options="field:'cwbh',align:'center',width:80">财务编号</th>
            <th data-options="field:'lqzymc',halign:'center',width:150">主修专业</th>
            <th data-options="field:'reason',halign:'center',width:150">冻结原因</th>
        </tr>
    </thead>
</table>
    </div>
</div>
<!-- 筛选学生的弹出框 -->
<div id="conditionWin2" class="easyui-window" title="请选择学生的筛选条件" style="width:460px;height:380px;padding-left:30px;padding-top:20px;"
        data-options="iconCls:'icon-save',modal:true,closed:true,minimizable:false,collapsible:false,maximizable:false">
	<table class="form_table" style="border:0px;">
		<tr><td>系：</td><td><input class="easyui-combobox" id="college2" style="width:240px;" value="-"
	    data-options="multiple:true,url:'uni/colleges',valueField:'lqyxsm',textField:'lqyxsmc',onSelect:checkIfAll2,onHidePanel:cascadeMajor2
	    	,loadFilter:function(data){return _.union([{id:0,lqyxsm:'-',lqyxsmc: '不限'}],data);}"></td></tr>
	    <tr><td>专业：</td><td><input class="easyui-combobox" id="major2" style="width:240px;" value="-" 
	    data-options="multiple:true,url:'uni/majors',valueField:'lqzydm',textField:'lqzymc',onSelect:checkIfAll2
	    	,loadFilter:function(data){return _.union([{id:0,lqzydm:'-',lqzymc: '不限'}],data);}"></td></tr>
	    <tr><td>年级：</td><td><input class="easyui-combobox" id="year2" style="width:240px;" value="-" 
	    data-options="multiple:true,url:'grant/years',valueField:'id',textField:'value',panelHeight:110,onSelect:checkIfAll2
	    	,loadFilter:function(data){return _.union([{id:'-',value: '不限'}],data);}"></td></tr>
	    <tr><td>类别：</td><td><input class="easyui-combobox" id="classify2" style="width:240px;" value="-" 
	    data-options="multiple:true,url:'grant/classify',valueField:'id',textField:'value',panelHeight:110,onSelect:checkIfAll2
	    	,loadFilter:function(data){return _.union([{id:'-',value: '不限'}],data);}"></td></tr>
	    <tr><td>所属名单：</td><td><input class="easyui-combobox" id="groupId2" style="width:240px;" value="-" 
	    data-options="multiple:true,url:'user/group',valueField:'id',textField:'name',panelHeight:110,onSelect:checkIfAll2
	    	,loadFilter:function(data){return _.union([{id:'-',name: '不限'}],data);}"></td></tr>
	    <tr><td></td><td><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="refreshStudents2()">确定</a>
	    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-no'" onclick="$('#conditionWin2').window('close');">取消</a></td></tr>
	</table>
</div>

<div id="freezeHisWin" class="easyui-window" title="冻结解冻历史" style="width:600px;height:480px;"
        data-options="iconCls:'icon-save',modal:true,closed:true,minimizable:false,collapsible:false,maximizable:false">
	<table class="easyui-datagrid" id="freezeHisList" 
	  		data-options="url:'user/freezeHis',fit:true,fitColumns:true,rownumbers:true,onBeforeLoad:function(param){return param.xh != undefined;}">
	  	<thead>
	        <tr>
	            <th data-options="field:'xm',halign:'center',width:60">姓名</th>
	            <th data-options="field:'action',align:'center',width:60">操作</th>
	            <th data-options="field:'createTime',align:'center',width:180">执行时间</th>
	            <th data-options="field:'startTime',align:'center',width:120,formatter:formatOnlyDate">冻结开始时间</th>
	            <th data-options="field:'endTime',align:'center',width:120,formatter:formatOnlyDate">冻结结束时间</th>
	            <th data-options="field:'reason',halign:'center',width:200">冻结/解冻原因</th>
	        </tr>
	    </thead>
	</table>
</div>

<script type="text/javascript" src="statics/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="statics/js/xdate.js"></script>

<!-- 冻结学生的弹出框 -->
<div id="freezeWin" class="easyui-window" title="冻结学生" style="width:280px;height:300px"
	data-options="iconCls:'icon-save',modal:true,closed:true,minimizable:false,collapsible:false,maximizable:false">
<table class="form_table" style="border:0px;">
	<tr><td colspan="2"><font color="red">若冻结已被冻结的学生，会覆盖原冻结信息！</font></td></tr>
	<tr><td>起始日期</td><td><input class="Wdate" id='startdate' type="text" style="width:130px;" onFocus="WdatePicker({isShowClear:false,readOnly:true})"/></td></tr>
	<tr><td>结束日期</td><td><input class="Wdate" id='enddate' type="text" style="width:130px;" onFocus="WdatePicker({isShowClear:false,readOnly:true})"/></td></tr>
	<tr><td>奖助学金</td><td><select id="scholarshipType3" class="select" style="width:132px"></select></td></tr>
	<tr><td>冻结原因</td><td><input type="text" id="reason" class="txtInput" style="width:124px;"></td></tr>
	<tr><td></td><td><input type="button" value="确定" class="btnSubmit" onclick="freezeStu()"></input>
	&nbsp;<input type="button" value="关闭" class="btnSubmit" onclick="$('freezeWin').window('close')"></input></td></tr>
</table>
</div>

<div id="thawWin" class="easyui-window" title="解冻学生" style="width:280px;height:150px"
	data-options="iconCls:'icon-save',modal:true,closed:true,minimizable:false,collapsible:false,maximizable:false">
<table class="form_table" style="border:0px;">
	<tr><td>奖助学金</td><td><select id="scholarshipType4" class="select" style="width:132px"></select></td></tr>
	<tr><td>解冻原因</td><td><input type="text" id="reason2" class="txtInput" style="width:124px;"></td></tr>
	<tr><td></td><td><input type="button" value="确定" class="btnSubmit" onclick="doThaw()"></input>
	&nbsp;<input type="button" value="关闭" class="btnSubmit" onclick="$('thawWin').window('close')"></input></td></tr>
</table>
</div>

<script type="text/javascript">
$(function(){
	var date = new XDate();
	$('#startdate').val(date.toString('yyyy-MM-dd'));
	$('#enddate').val(date.addYears(1).toString('yyyy-MM-dd'));

	$.ajax({
		url:'uni/scholars',
		success:function(scholarshipTypes) {
			var options = $.map(scholarshipTypes,function(row) {
				return '<option value="' + row.id + '">' + row.name + '</option>';
			}).join('');
			$('#scholarshipType3,#scholarshipType4').html('<option value="-">全部</option>' + options);
		}
	});
});

var smToolbar = [{
    text:'冻结',
    iconCls:'icon-add',
    handler:freezeWin
},{
    text:'解冻',
    iconCls:'icon-remove',
    handler:thaw
}];

function checkIfAll2(record) {
	if(record[$(this).combobox('options').valueField] == '-') {
		$(this).combobox('setValue','-');
	} else {
		$(this).combobox('unselect','-');
	}
}

function cascadeMajor2() {
	var college = $('#college2').combobox('getValues').join(',');
	$('#major2').combobox('reload','uni/majors' + (college == '-'? '':'?college=' + college));
}

function refreshStudents2() {
	var info = '学院:' + $('#college2').combobox('getText') + ',' +
			'专业:' + $('#major2').combobox('getText') + ',' +
			'年级:' + $('#year2').combobox('getText') + ',' +
			'类别:' + $('#classify2').combobox('getText') + ',' +
			'所属名单:' + $('#groupId2').combobox('getText');
	$('#currentCondition2').html(info);
	$('#currentCondition2').attr('title',info);

	$('#smList').datagrid('reload',
		{college:$('#college2').combobox('getValues').join(','),
		major:$('#major2').combobox('getValues').join(','),
		year:$('#year2').combobox('getValues').join(','),
		classify:$('#classify2').combobox('getValues').join(','),
		groupId:$('#groupId2').combobox('getValues').join(',')});
	
	$('#conditionWin2').window('close');
}

function formatOnlyDate(val,row) {
	return val && val.length > 10 ? val.substr(0,10):val;
}

function formatNameLink(val,row) {
	return '<a href="javascript:void(0)" style="color:blue;" onclick="showFreezeHis(\'' + row.xh + '\')">' + val + '</a>';
}

function showFreezeHis(xh) {
	$('#freezeHisList').datagrid('load',{xh: xh});
	$('#freezeHisWin').window('open');
}

function stuRowStyler2(index,row) {
	if(row.freeze) {return 'background-color:#F0F0F0;color:#979797;';}
}

function freeStuRender2(data) {
	var freezeList = $.parseJSON($.ajax({url: "user/freezeList",async: false}).responseText);
	var freezeXhs = $.map(freezeList,function(row){return row.xh;});
	$.each(data.rows,function(id,row) {//标记冻结学生
		if($.inArray(row.xh,freezeXhs) > -1) {row.freeze = true;row.xm = row.xm + '[已冻结]';}
	});
	return data;
}

function freezeStu() {
	var xhs = $.map($('#smList').datagrid('getChecked'),function(row){return row.xh;}).join(',');
	
	$.ajax({
		url:'user/freeze',
		type:'POST',
		data:'xhs=' + xhs + '&startdate=' + $('#startdate').val() + '&enddate=' + $('#enddate').val()
			+ '&reason=' + $('#reason').val() + '&scholarshipId=' +　$('#scholarshipType3').val(),
		success:function(result) {
			if(result.errorInfo != 'none') {
				$.messager.alert('提示',result.errorInfo);
				return;
			} 
			$('#smList').datagrid('reload');
			$.messager.alert('提示','冻结成功！');
			$('#freezeWin').window('close');
		}
	});
}

function freezeWin() {
	var checkedList = $('#smList').datagrid('getChecked');
    if(checkedList.length == 0) {
		$.messager.alert('提示','请至少选择一个学生！');
		return;
    }
	$('#freezeWin').window('open');
}

function thaw() {
	var selectedXhs = $.map($('#smList').datagrid('getChecked'),function(row){return row.xh;});

	if(selectedXhs.length == 0) {
		$.messager.alert('提示','你没有选择任何学生！');
		return;
	}

	var freezeList = $.parseJSON($.ajax({url: "user/freezeList",async: false}).responseText);
	var freezeXhs = $.map(freezeList,function(row){if($.inArray(row.xh,selectedXhs) > -1)return row.xh;});

	if(freezeXhs.length == 0) {
		$.messager.alert('提示','你选择的学生中不存在冻结的名单！');
		return;
	}
	
	$('#thawWin').window('open');
}

function doThaw() {
	var selectedXhs = $.map($('#smList').datagrid('getChecked'),function(row){return row.xh;});
	var freezeList = $.parseJSON($.ajax({url: "user/freezeList",async: false}).responseText);
	var freezeXhs = _.uniq($.map(freezeList,function(row){if($.inArray(row.xh,selectedXhs) > -1)return row.xh;}));

	console.log(selectedXhs);
	console.log(freezeList);
	console.log(freezeXhs);
	
	$.ajax({
		url:'user/thaw',
		type:'POST',
		data:'xhs=' + freezeXhs.join(',') + '&reason=' + $('#reason2').val() + '&scholarshipId=' + $('#scholarshipType4').val(),
		success:function(result) {
			if(result.errorInfo != 'none') {
				$.messager.alert('提示',result.errorInfo);
				return;
			} 
			$('#smList').datagrid('reload');
			$('#thawWin').window('close');
			$.messager.alert('提示','解冻成功！');
		}
	});
}
</script>